package com.inkegz.message.repo.action

import android.util.Log
import com.inkegz.message.entity.MessageEntity
import com.inkegz.message.repo.base.ObjectBoxAction
import com.inkegz.message.repo.base.ObjectBoxState
import com.inkegz.message.utils.messageBox
import com.inkegz.message.utils.queryMessage
import io.objectbox.query.Query

/**
 * 删除 消息 操作
 */
class RemoveMessageAction(
    private val messageVersionId: Long
) :ObjectBoxAction(){
    override suspend fun opt(state: ObjectBoxState): ObjectBoxState {
        val message = state.queryMessage(messageVersionId)
            ?: run {
                Log.e("ImRepo", "can not find message when remove message")
                return state
            }
        state.messageBox().remove(message)
        return ObjectBoxState(state.model)
    }
}